<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/7/18
 * Time: 16:56
 */

namespace app\common\model;


use think\Model;

class BusBusinessUser extends Model
{

    public function business(){
        return $this->hasOne('BusBusiness', 'id', 'business_id')->
                    bind([
                        'business_name' => 'name',
                        'business_img' => 'thumb',
                        'business_status' => 'status',
                    ]);
    }

    public function role(){
        return $this->hasOne('Role', 'id', 'role_id')->
        bind([
            'role_name' => 'name',
        ]);
    }

    public function setPasswordAttr($value, $data){
        return pwdMd5($value, $data['salt']);
    }

    public function setIsAdminAttr(){
        
    }

    public function getRoleTextAttr($value, $data){
        if ($data['is_admin']){
            return '管理员';
        } else{
            return $data['role_name'];
        }
    }

}